package com.ayguigu.order.controller;

import com.atguigu.order.bean.Order;
import com.ayguigu.order.properties.OrderProperties;
import com.ayguigu.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * OrderController
 *
 * @author Mars
 * @date 2025/3/14
 */

//@RefreshScope // 自动刷新配置
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

//    @Value("${order.timeout}")
//    String orderTimeout;
//
//    @Value("${order.autoConfirm}")
//    String orderAutoConfirm;

    @Autowired
    OrderProperties orderProperties;

    @GetMapping("/config")
    public String config() {
        return "order.timeout:" + orderProperties.getTimeout()+"；" +
                "order.auto-Confirm:" + orderProperties.getAutoConfirm()+"；"  +
                "order.db-url=" + orderProperties.getDbUrl();
//        return "order.timeout:" + orderTimeout + ",order.auto-Confirm:" + orderAutoConfirm;
    }

    // 创建订单
    @GetMapping("/create")
    public Order createOrder(@RequestParam("userId") Long userId,
                             @RequestParam("productId") Long productId) {
        return orderService.createOrder(productId, userId);
    }

}